package com.kaifamiao.demo.d0906;

import java.sql.*;

public class Demo {

    public static void main(String[] args) {
        // 注册驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/kfm";
        String sql = "{CALL proc_total(?, ?)}";
        try( // 创建连接
             Connection conn = DriverManager.getConnection(url, "root", "");
             CallableStatement callableStatement = conn.prepareCall(sql);
             ) {

            // 设置参数
            // IN
            callableStatement.setInt(1, 7788);
            // OUT
            callableStatement.registerOutParameter(2, Types.DOUBLE);

            // 执行
            callableStatement.execute();

            double aDouble = callableStatement.getDouble(2);
            System.out.println(aDouble);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
